function compile_mex(type)
% COMPILE_MEX  Compile MEX files
%   Compiling under Windows requires at least Visual C 6 or LCC. You
%   might try other compilers, but most likely you will need to edit
%   this file.
%
%   Originally created by Andrea Vedaldi for SIFT
%	UCLA Vision Lab - Department of Computer Science
%
% 	Adapted by Wei Liu for flow field singular pattern detection
% 	Bio-inspired Computing and Computer Vision lab
%	Florida Institute of Technology - Department of Computer Science
siftroot = fileparts(which('siftcompile')) ;
opts = { '-O', '-I.', '-g' } ;
opts = { opts{:}, '-v' } ;

if nargin < 1
    type = 'visualc' ;
end

switch computer
  case {'PCWIN', 'PCWIN64'}
    opts = {opts{:}, '-DWINDOWS'} ;

  case 'MAC'
    opts = {opts{:}, '-DMACOSX'} ;
    opts = {opts{:}, 'CFLAGS=\$CFLAGS -faltivec'} ;

  case 'MACI'
    opts = {opts{:}, '-DMACOSX'} ;

  case 'MACI64'
    opts = {opts{:}, '-DMACOSX'} ;
    
  case {'GLNX86', 'GLNXA64'}
    opts = {opts{:}, '-DLINUX' } ;

  otherwise
    error(['Unsupported architecture ', computer, '. Please edit this M-file to fix the issue.']) ;
end

% files borrowed from SIFT
mex('imsmooth.c',opts{:}) ;
mex('siftlocalmax.c',opts{:}) ;
% files for finding polynomial roots. I'm not really using the C code here.
% cd poly;
% mex('sing_energy_c.c', 'null.c','complex.c','tools.c','newton.c','muller.c',opts{:});
% copyfile sing_energy_c.mexw32 ../
% cd ..



